//
//  LTBaseTabBarController.m
//  XHLKit
//
//  Created by qinyulun on 16/6/18.
//  Copyright © 2016年 leTian. All rights reserved.
//

#import "LTBaseTabBarController.h"
#import "LTTabBar.h"
#import "LTBaseNavigationController.h"

#import "ViewController.h"

@implementation LTBaseTabBarController

+ (void)initialize
{
    UITabBarItem *appearance = [UITabBarItem appearance];
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    [appearance setTitleTextAttributes:attrs forState:UIControlStateSelected];
    
    [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabbar-light"]];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 替换tabbar
    [self setValue:[[LTTabBar alloc] init] forKeyPath:@"tabBar"];
    
    // 初始化所有的子控制器
    [self setupChildViewControllers];
    
    
}




/**
 * 初始化所有的子控制器
 */
- (void)setupChildViewControllers
{
    
    ViewController *essence = [[ViewController alloc] init];
    essence.view.backgroundColor = [UIColor redColor];
    [self setupOneChildViewController:essence title:@"首页" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    
    UIViewController *new = [[UIViewController alloc] init];
    new.view.backgroundColor = [UIColor yellowColor];
    [self setupOneChildViewController:new title:@"商城" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    
    UIViewController *friends = [[UIViewController alloc] init];
    friends.view.backgroundColor = [UIColor whiteColor];
    [self setupOneChildViewController:friends title:@"购物车" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    
    UIViewController *me = [[UIViewController alloc] init];
    me.view.backgroundColor = [UIColor blueColor];
    [self setupOneChildViewController:me title:@"我的" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
}

- (void)setupOneChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    [self addChildViewController:[[LTBaseNavigationController alloc] initWithRootViewController:vc]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
